package org.shenba.springbible.services.impl;

import java.util.ArrayList;

import org.shenba.springbible.models.Bible;
import org.shenba.springbible.services.KJVService;
import org.shenba.springbible.util.XMLGrabber;
import org.springframework.stereotype.Service;

@Service
public class KJVServiceImpl implements KJVService {
	
	/* (non-Javadoc)
	 * @see org.shenba.springbible.services.KJVService#getBookList()
	 */
	public ArrayList<String> getBookList() {
		return XMLGrabber.getListOfBooks();
	}
	
	/* (non-Javadoc)
	 * @see org.shenba.springbible.services.KJVService#getChapterList(org.shenba.springbible.models.Bible)
	 */
	public ArrayList<String> getChapterList(Bible bible) {
		ArrayList<String> chapterList = new ArrayList<String>();
		int totalChapters = XMLGrabber.getChapters(bible.getBook());
		for (int i = 0; i < totalChapters; i++) {
			chapterList.add(String.valueOf(i+1));
		}
		return chapterList;
	}
	
	/* (non-Javadoc)
	 * @see org.shenba.springbible.services.KJVService#getVerseList(org.shenba.springbible.models.Bible)
	 */
	public ArrayList<String> getVerseList(Bible bible) {
		ArrayList<String> chapterList = new ArrayList<String>();
		int totalVerses = XMLGrabber.getVerses(bible.getBook(), bible.getChapter());
		for (int i = 0; i < totalVerses; i++) {
			chapterList.add(String.valueOf(i+1));
		}
		return chapterList;
	}
	
	/* (non-Javadoc)
	 * @see org.shenba.springbible.services.KJVService#getSelectedVerse(org.shenba.springbible.models.Bible)
	 */
	public String getSelectedVerse(Bible bible) {
		return XMLGrabber.getVerse(bible.getBook(), bible.getChapter(), bible.getVerse());
	}
	
}
